package com.share.starter.oss.autoconfigure;

import com.aliyun.oss.OSSClient;
import com.share.starter.oss.annotations.EnableOss;
import com.share.starter.oss.config.AutoConfigruationProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(AutoConfigruationProperties.class)
@ConditionalOnClass(EnableOss.class)
public class OssAutoConfigure {

    @Autowired
    private AutoConfigruationProperties ossConfig;

    @Bean
    @ConditionalOnMissingBean
    public OSSClient getHashCodeClass() {
        return new OSSClient(ossConfig.getEndpoint(), ossConfig.getAccessKeyId(), ossConfig.getAccessKeySecret());
    }
}